home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d3
/
rettig.arc
/
TRSOURCE.EXE
/
LEADCHAR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-22
|
1KB
|
56 lines
/*********
* LEADCHAR.C
*
* by Tom Rettig
*
* Placed in the public domain by Tom Rettig Associates, 10/22/1990.
*
* Syntax: LEADCHAR( <expC>, <char> )
* Return: <expC> with each leading space replaced by <char>.
* Unchanged if <char> omitted or null, or if out of memory.
* Note : Return string is same length as <expC>.
*********/
#include "trlib.h"
TRTYPE leadchar()
{
char *instr, *replace, *ret;
int i, j;
static char funcname[] = { "leadchar" };
if ( PCOUNT==2 && ISCHAR(1) && ISCHAR(2) )
{
instr = _parc(1);
replace = _parc(2);
ret = _tr_allocmem((unsigned)(_tr_strlen(instr)+1));
if ( ret )
{
if (instr[0]==SPACEC && replace[0] )
{
for ( i=j=0; instr[j]==SPACEC; i++, j++ )
ret[i] = replace[0];
for ( ; instr[j]; i++, j++ )
ret[i] = instr[j];
ret[i] = NULLC;
_retc( ret );
}
else /* return unchanged if no leading spaces, or null replace */
_retc( instr );
_tr_freemem( ret,(unsigned)(_tr_strlen(instr)+1));
}
else /* return unchanged if no memory */
_retc( instr );
}
else
if ( PCOUNT==1 && ISCHAR(1) )
_retc( _parc(1) );
else
_retc( _tr_errmsgs(funcname,E_SYNTAX) );
}